﻿using System;
using System.Windows.Forms;
using System.ComponentModel;

namespace NSGetData
{
    public partial class GraphicCmdLabFrom : Form
    {
        public GraphicCmdLabFrom()
        {
            InitializeComponent();
            this.TopMost = false;
            this.comboBox_staticLoad.DropDownStyle = ComboBoxStyle.DropDownList; // 设置为下拉列表
            this.comboBox_staticLoad.Items.Clear();
            this.comboBox_staticLoad.Items.AddRange(Enum.GetNames(typeof(LoadCaseDef)));
            this.comboBox_staticLoad.SelectedItem = LoadCaseDef.恒载.ToString();
            this.TopMost = true;
        }
        private void GraphicCmdLabFrom_Load(object sender, EventArgs e) { }
        private void GraphicCmdLabFrom_Activated(object sender, EventArgs e) { }
        private void comboBox_staticLoad_SelectedIndexChanged(object sender, EventArgs e) { }
        private void button_cancel_Click(object sender, EventArgs e) { this.Close(); }
        private void btnSend_Click(object sender, EventArgs e)
        {
            NSSP3DBase nSSP3DCommand = new NSSP3DBase();
            nSSP3DCommand.SendHeZaiBollToGAMA();
        }
        private void backgroundWorker_send_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            NSSP3DBase nSSP3DCommand = new NSSP3DBase();
            nSSP3DCommand.SendHeZaiBollToGAMA();
            for (int i = 0; i < 100; i++)
            {
                worker.ReportProgress(i);
                System.Threading.Thread.Sleep(100);
            }
        }
        private void GetLoadDef()
        {
            if (radioButton_Dynamic.Checked)
            {
                GetNSLoadDef(GraphicFormCommand.NSLiveLoadDef);
            }
            if (radioButton_Static.Checked)
            {
                GetNSLoadDef(GraphicFormCommand.NSDeadLoadDef);
            }
        }
        private void GetNSLoadDef(NSLoadDef loadDef)
        {
            Enum.TryParse(comboBox_staticLoad.SelectedItem.ToString(), out LoadCaseDef result);
            loadDef.LoadCase = result;
            loadDef.SelfDefine = Convert.ToBoolean(checkBox_selfDefine.Checked);
            loadDef.GravityProxy = Convert.ToDouble(textBox_gravityProxy_S.Text);
            loadDef.AdNonSeiCoefficient = Convert.ToDouble(textBox_adNonSeiCoefficient_S.Text);
            loadDef.BenNonSeiCoefficient = Convert.ToDouble(textBox_benNonSeiCoefficient_S.Text);
            loadDef.AdSeiCoefficient = Convert.ToDouble(textBox_adSeiCoefficient_S.Text);
            loadDef.BenSeiCoefficient = Convert.ToDouble(textBox_benSeiCoefficient_S.Text);
            loadDef.NonSesimicCoefficient = Convert.ToDouble(textBox_nonSesimicCoefficient_S.Text);
            loadDef.SesimicCoefficient = Convert.ToDouble(textBox_sesimicCoefficient_S.Text);
            loadDef.FreComCoefficient = Convert.ToDouble(textBox_freComCoefficient_S.Text);
            loadDef.QuasiPreComCoefficient = Convert.ToDouble(textBox_quasiPreComCoefficient_S.Text);
            loadDef.WallDisCoefficient = Convert.ToDouble(textBox_wallDisCoefficient_S.Text);
            loadDef.MainBeamDisCoefficient = Convert.ToDouble(textBox_mainBeamDisCoefficient_S.Text);
            loadDef.SecBeamDisCoefficient = Convert.ToDouble(textBox_secBeamDisCoefficient_S.Text);
        }
        private void DisPlayNumber()
        {
            if (radioButton_Static.Checked)
            {
                DisplayLoad(GraphicFormCommand.NSDeadLoadDef);
            }
            else if (radioButton_Dynamic.Checked)
            {
                DisplayLoad(GraphicFormCommand.NSLiveLoadDef);
            }
        }
        private void DisplayLoad(NSLoadDef loadDef)
        {
            comboBox_staticLoad.SelectedItem = loadDef.LoadCase.ToString();
            checkBox_selfDefine.Checked = loadDef.SelfDefine;
            textBox_gravityProxy_S.Text = loadDef.GravityProxy.ToString("F2");
            textBox_adNonSeiCoefficient_S.Text = loadDef.AdNonSeiCoefficient.ToString("F2");
            textBox_benNonSeiCoefficient_S.Text = loadDef.BenNonSeiCoefficient.ToString("F2");
            textBox_adSeiCoefficient_S.Text = loadDef.AdSeiCoefficient.ToString("F2");
            textBox_benSeiCoefficient_S.Text = loadDef.BenSeiCoefficient.ToString("F2");
            textBox_nonSesimicCoefficient_S.Text = loadDef.NonSesimicCoefficient.ToString("F2");
            textBox_sesimicCoefficient_S.Text = loadDef.SesimicCoefficient.ToString("F2");
            textBox_freComCoefficient_S.Text = loadDef.FreComCoefficient.ToString("F2");
            textBox_quasiPreComCoefficient_S.Text = loadDef.QuasiPreComCoefficient.ToString("F2");
            textBox_wallDisCoefficient_S.Text = loadDef.WallDisCoefficient.ToString("F2");
            textBox_mainBeamDisCoefficient_S.Text = loadDef.MainBeamDisCoefficient.ToString("F2");
            textBox_secBeamDisCoefficient_S.Text = loadDef.SecBeamDisCoefficient.ToString("F2");
        }

        private void radioButton_Static_CheckedChanged(object sender, EventArgs e)
        {
            GetLoadDef();
            DisPlayNumber();
        }
        private void button_Export_Click(object sender, EventArgs e)
        {
            GetLoadDef();
            NSSP3DBase.SaveAsJson();
        }

        private void button_import_Click(object sender, EventArgs e)
        {
            NSSP3DBase.ReadFromJson();
            DisPlayNumber();
        }
    }
}
